home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF Maintain CDF information for OBSOLETE interface.
- *
- * Version 1.2, 10-Feb-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 22-Jan-91, J Love Original version (for CDF V2.0).
- * V1.1 20-Sep-91, J Love Modified for IBM-PC port.
- * V1.2 10-Feb-92, J Love CDF V2.2.
- *
- ******************************************************************************/
-
- #if defined(vms) /* THIS FILE ONLY USED ON VMS SYSTEMS */
-
- #include "cdflib.h"
-
- struct attrInfoStruct {
- long attrNum;
- long dataType;
- long numElements;
- Boolean compatible;
- struct attrInfoStruct *next;
- };
-
- struct CDFinfoStruct {
- CDFid id;
- struct attrInfoStruct *attrHeader;
- struct CDFinfoStruct *next;
- };
-
- static struct CDFinfoStruct *CDFheader = NULL;
-
-
- /******************************************************************************
- * initializeCDFinfo.
- ******************************************************************************/
-
- CDFstatus initializeCDFinfo (id)
- CDFid id;
- {
- struct CDFinfoStruct *CDFptr;
- struct CDFinfoStruct *CDFtrailer;
-
- if (CDFheader == NULL) {
- CDFptr = (struct CDFinfoStruct *) malloc (sizeof(struct CDFinfoStruct));
- if (CDFptr == NULL) return BAD_MALLOC;
-
- CDFptr->id = id;
- CDFptr->attrHeader = NULL;
- CDFptr->next = NULL;
-
- CDFheader = CDFptr;
- }
- else {
- CDFptr = CDFheader;
-
- while (CDFptr != NULL) {
- if (CDFptr->id == id) {
- freeAttrInfo (CDFptr->attrHeader);
- CDFptr->attrHeader = NULL;
- break;
- }
-
- CDFtrailer = CDFptr;
- CDFptr = CDFptr->next;
- }
-
- if (CDFptr == NULL) {
- CDFptr = (struct CDFinfoStruct *) malloc (sizeof(struct CDFinfoStruct));
- if (CDFptr == NULL) return BAD_MALLOC;
-
- CDFptr->id = id;
- CDFptr->attrHeader = NULL;
- CDFptr->next = NULL;
-
- CDFtrailer->next = CDFptr;
- }
- }
-
- return inquireCDFinfo (id, CDFptr);
- }
-
-
- /******************************************************************************
- * inquireCDFinfo.
- ******************************************************************************/
-
- CDFstatus inquireCDFinfo (id, CDFptr)
- CDFid id;
- struct CDFinfoStruct *CDFptr;
- {
- CDFstatus Status;
- long numDims;
- long dimSizes[CDF_MAX_DIMS];
- long encoding;
- long majority;
- long numRecs;
- long numVars;
- long numAttrs;
- long attrNum;
- long entryNum;
- long dataType;
- long numElements;
- long attrScope;
- long maxEntry;
- char attrName[CDF_ATTR_NAME_LEN+1];
-
- Status = CDFinquire (id, &numDims, dimSizes, &encoding, &majority,
- &numRecs, &numVars, &numAttrs);
- if (Status < CDF_OK) return Status;
-
- for (attrNum = 0; attrNum < numAttrs; attrNum++) {
- Status = CDFattrInquire (id, attrNum, attrName, &attrScope, &maxEntry);
- if (Status < CDF_OK) return Status;
-
- for (entryNum = 0; entryNum <= maxEntry; entryNum++) {
- Status = CDFattrEntryInquire (id, attrNum, entryNum, &dataType,
- &numElements);
- if (Status == NO_SUCH_ENTRY)
- break;
- else
- if (Status < CDF_OK)
- return Status;
- else {
- Status = putAttrInfo (id, attrNum, dataType, numElements);
- if (Status < CDF_OK) return Status;
- break;
- }
- }
- }
-
- return CDF_OK;
- }
-
-
- /******************************************************************************
- * freeAttrInfo.
- ******************************************************************************/
-
- void freeAttrInfo (attrPtr)
- struct attrInfoStruct *attrPtr;
- {
- struct attrInfoStruct *nextAttrPtr;
-
- while (attrPtr != NULL) {
- nextAttrPtr = attrPtr->next;
- free (attrPtr);
- attrPtr = nextAttrPtr;
- }
-
- return;
- }
-
-
- /******************************************************************************
- * putAttrInfo.
- ******************************************************************************/
-
- CDFstatus putAttrInfo (id, attrNum, dataType, numElements)
- CDFid id;
- long attrNum;
- long dataType;
- long numElements;
- {
- struct CDFinfoStruct *CDFptr;
- struct attrInfoStruct *attrPtr;
- struct attrInfoStruct *attrTrailer = NULL;
-
- CDFptr = CDFheader;
-
- while (CDFptr != NULL) {
- if (CDFptr->id == id) {
- attrPtr = CDFptr->attrHeader;
-
- while (attrPtr != NULL) {
- if (attrPtr->attrNum == attrNum) {
- if (attrPtr->dataType != dataType ||
- attrPtr->numElements != numElements)
- attrPtr->compatible = FALSE;
- return CDF_OK;
- }
-
- attrTrailer = attrPtr;
- attrPtr = attrPtr->next;
- }
-
- attrPtr = (struct attrInfoStruct *)
- malloc (sizeof(struct attrInfoStruct));
- if (attrPtr == NULL) return BAD_MALLOC;
-
- attrPtr->attrNum = attrNum;
- attrPtr->dataType = dataType;
- attrPtr->numElements = numElements;
- attrPtr->compatible = TRUE;
- attrPtr->next = NULL;
-
- if (attrTrailer == NULL)
- CDFptr->attrHeader = attrPtr;
- else
- attrTrailer->next = attrPtr;
-
- return CDF_OK;
- }
-
- CDFptr = CDFptr->next;
- }
-
- return BAD_CDF_ID;
- }
-
-
- /******************************************************************************
- * getAttrInfo.
- ******************************************************************************/
-
- CDFstatus getAttrInfo (id, attrNum, dataType, numElements)
- CDFid id;
- long attrNum;
- long *dataType;
- long *numElements;
- {
- struct CDFinfoStruct *CDFptr;
- struct attrInfoStruct *attrPtr;
- struct attrInfoStruct *attrTrailer;
-
- CDFptr = CDFheader;
-
- while (CDFptr != NULL) {
- if (CDFptr->id == id) {
- attrPtr = CDFptr->attrHeader;
-
- while (attrPtr != NULL) {
- if (attrPtr->attrNum == attrNum)
- if (attrPtr->compatible) {
- *dataType = attrPtr->dataType;
- *numElements = attrPtr->numElements;
- return CDF_OK;
- }
- else
- return CDF_INCOMPATIBLE;
-
- attrPtr = attrPtr->next;
- }
-
- return NO_SUCH_ATTR;
- }
-
- CDFptr = CDFptr->next;
- }
-
- return BAD_CDF_ID;
- }
-
- #endif
-